#include "timer_task.hpp"
#include <unistd.h>
#include <regex>
#include <string>
using namespace std;


class a {
public:
    a() {
        cout << "a created" << endl;
    }
    ~a() {
        cout << "a destroyed" << endl;
    }
};

void del_a(const a* p) {
    delete p;
}

void test_wheel() {
    time_wheel tw;
    a *aa = new a;
    tw.add_task(666, 3, bind(del_a, aa));
    for(int i = 0; i < 5; ++i) {
        tw.task_refresh(666);
        tw.tick();
        cout << "refresh ..." << endl;
        sleep(1);
    }
    tw.set_task_cancel(666);
    while(1) {
        cout << "tick....." << endl;
        tw.tick();
        sleep(1);
    }
}

void test_regex() {
    std::string str = "/numbers/1234";
    //匹配以 /numbers/起始，后边跟了一个或多个数字字符的字符串，并且在匹配的过程中提取这个匹配到的数字字符串
    std::regex e("/numbers/(\\d+)");
    std::smatch matches;

    bool ret = std::regex_match(str, matches, e);
    if (ret == false) {
        return;
    }
    for (auto &s : matches) {
        std::cout << s << std::endl;
    }  
}

int main() {
    // test_wheel();
    test_regex();
    return 0;
}